#include "manageformtitle.h"
#include <QHBoxLayout>
#include <QPainter>
#include <QFile>
#include <QMouseEvent>
#include <QApplication>
#include "custombox.h"
#include <QButtonGroup>

ManageFormTitle::ManageFormTitle(QWidget *parent)
    : QWidget(parent)
{
    QLabel* NpTitleContent = new QLabel();
    QPushButton* NpButtonClose = new QPushButton();

    NpTitleContent->setObjectName("TitleText");
    NpButtonClose->setFixedSize(QSize(24, 24));
    NpButtonClose->setObjectName("NButtonClose");

    QHBoxLayout* BoxLayout = new QHBoxLayout(this);
    BoxLayout->addWidget(NpTitleContent);
    BoxLayout->addWidget(NpButtonClose);

    BoxLayout->setContentsMargins(5, 0, 5, 0);
    BoxLayout->setSpacing(0);

    NpTitleContent->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

    NpButtonClose->setFocusPolicy(Qt::NoFocus);

    NpButtonClose->setCursor(Qt::PointingHandCursor);

    setFixedHeight(30);
    setWindowFlags(Qt::FramelessWindowHint);

    QObject::connect(NpButtonClose, SIGNAL(clicked()), this, SLOT(OnNewCloseClicked()));

    setStyleSheet(
        "QLabel#TitleText{color:yellow;padding-left:3px;font:12pt'Microsoft YaHei';}"
        "QPushButton#NButtonClose{border-image:url(:/Resources/Close1.png);border-top-right-radius:3;}"
        "QPushButton#NButtonClose:hover{border-image:url(:/Resources/Close3.png);border-top-right-radius:3;}"
        "QPushButton#NButtonClose:pressed{border-image:url(:/Resources/Close2.png);border-top-right-radius:3;}"
    );
}

ManageFormTitle::~ManageFormTitle() {}

//设置标题栏长度
void ManageFormTitle::SetTitleWidth(int Width)
{
    this->setFixedWidth(Width);
}

void ManageFormTitle::OnNewCloseClicked()
{
    emit NButtonCloseClicked();
}
